package com.masterclient.app.modules.firstpager.fragments.adapters;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.eoner.managerlibrary.router.AroutePath;
import com.masterclient.app.App;
import com.masterclient.app.R;
import com.eoner.baselibrary.bean.firstpager.RecommendPagerBean;
import com.eoner.baselibrary.utils.ScreenUtils;

/**
 * 作者：sean
 * 创建时间：2017/12/18 16:26
 * 功能说明：
 */

public class SpecialGoodsAdapter extends BaseQuickAdapter<RecommendPagerBean.DataBean.ShRemCollectionBean.ShCollectionsBean.ShCmsProductsBean,BaseViewHolder>{

    public SpecialGoodsAdapter() {
        super(R.layout.item_specail_goods);
    }

    @Override
    protected void convert(BaseViewHolder helper, RecommendPagerBean.DataBean.ShRemCollectionBean.ShCollectionsBean.ShCmsProductsBean item) {
        helper.setText(R.id.tv_name,item.getSh_name());
        if(!TextUtils.isEmpty(item.getSh_image())){
            App.picasso.load(item.getSh_image())
                    .resize(ScreenUtils.dp2px(100),ScreenUtils.dp2px(100))
                    .into((ImageView) helper.getView(R.id.iv_product));
        }
//        ImageView ivActivity = helper.getView(R.id.iv_activity);

        ImageView ivTagNew = helper.getView(R.id.iv_tag_new);
        ImageView ivShouqing = helper.getView(R.id.iv_shouqing);
        LinearLayout ll_earn = helper.getView(R.id.ll_earn);
        TextView tv_price = helper.getView(R.id.tv_price);
        TextView tv_price_now = helper.getView(R.id.tv_price_now);
        TextView tv_money_earn = helper.getView(R.id.tv_money_earn);
        LinearLayout llGood = helper.getView(R.id.ll_good);

        llGood.setOnClickListener(v->{
            ARouter.getInstance().build(AroutePath.COMMODITY_DETAIL_ACTIVITY)
                    .withString("id", item.getSh_id())
                    .navigation();
        });

        tv_price_now.setText("¥"+item.getSh_show_price());

        if(0==Double.valueOf(item.getSh_partner_commission())){
            tv_price_now.setVisibility(View.VISIBLE);
            ll_earn.setVisibility(View.GONE);
        }else {
            tv_price.setText("¥"+item.getSh_show_price());
            tv_money_earn.setText("赚"+item.getSh_partner_commission());
            tv_price_now.setVisibility(View.GONE);
            ll_earn.setVisibility(View.VISIBLE);
        }

        if(Integer.valueOf(item.getSh_stock())<=0){
            ivShouqing.setVisibility(View.VISIBLE);
        }else {
            ivShouqing.setVisibility(View.GONE);
        }

        if("1".equals(item.getSh_is_new())){
            ivTagNew.setVisibility(View.VISIBLE);
        }else {
            ivTagNew.setVisibility(View.GONE);
        }



/*        if(item.getSh_label()!=null
                && !TextUtils.isEmpty(item.getSh_label().getSh_icon_height())
                &&!TextUtils.isEmpty(item.getSh_label().getSh_icon_width())) {
            App.picasso.load(item.getSh_label().getSh_icon()).fit().into(ivActivity);
            ivActivity.setVisibility(View.VISIBLE);
            RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) ivActivity.getLayoutParams();
            params.height = ScreenUtils.dp2px(Integer.valueOf(item.getSh_label().getSh_icon_height()) / 2);
            params.width = ScreenUtils.dp2px(Integer.valueOf(item.getSh_label().getSh_icon_width()) / 2);
            switch (item.getSh_label().getSh_location()) {
                case "left_top":
                    params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
                    break;
                case "right_top":
                    params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
                    break;
                case "left_bottom":
                    params.addRule(RelativeLayout.ALIGN_BOTTOM,R.id.iv_goods);
                    params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
                    params.setMargins(ScreenUtils.dp2px(7), 0, 0, ScreenUtils.dp2px(7));
                    break;
                case "right_bottom":
                    params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
                    params.addRule(RelativeLayout.ALIGN_BOTTOM,R.id.iv_goods);
                    params.setMargins(0, 0, ScreenUtils.dp2px(7), ScreenUtils.dp2px(7));
                    break;
            }
            ivActivity.setLayoutParams(params);
        }*/

    }
}
